package cn.com.ghy.android.bean;

import java.io.Writer;

import org.xmlpull.v1.XmlSerializer;

import android.util.Xml;
import cn.com.ghy.android.util.XMLStatic;

public class NewCustomerInfoBeanParser {
	public static String createXML(NewCustomerInfoBean bean, LoginInfoBean loginInfo,
			Writer writer) throws Exception {
        XmlSerializer xmlSerializer = Xml.newSerializer();
        
        xmlSerializer.setOutput(writer);
        xmlSerializer.startDocument("UTF-8", true);
        xmlSerializer.startTag("", XMLStatic.CONTENT);
        xmlSerializer.attribute("", XMLStatic.TOTAL_RECORD, "1");
        xmlSerializer.startTag("", XMLStatic.RECORDS);
        
        xmlSerializer.startTag("", XMLStatic.NAME_ORG1);
        xmlSerializer.text(bean.getCustomerName());
		xmlSerializer.endTag("", XMLStatic.NAME_ORG1);
		
        xmlSerializer.startTag("", XMLStatic.STREET);
        xmlSerializer.text(bean.getAddr());
		xmlSerializer.endTag("", XMLStatic.STREET);
		xmlSerializer.startTag("", XMLStatic.CITY);
        xmlSerializer.text(bean.getCity());
        xmlSerializer.endTag("", XMLStatic.CITY);
    	xmlSerializer.startTag("", XMLStatic.ZONE);
        xmlSerializer.text(bean.getCounty());
		xmlSerializer.endTag("", XMLStatic.ZONE);
		xmlSerializer.startTag("", XMLStatic.JDB);
        xmlSerializer.text(bean.getJdb());
		xmlSerializer.endTag("", XMLStatic.JDB);
		xmlSerializer.startTag("", XMLStatic.LXR);
        xmlSerializer.text(bean.getContacts());
		xmlSerializer.endTag("", XMLStatic.LXR);
		xmlSerializer.startTag("", XMLStatic.LXDH);
        xmlSerializer.text(bean.getPhone());
		xmlSerializer.endTag("", XMLStatic.LXDH);
		xmlSerializer.startTag("", XMLStatic.YT);
        xmlSerializer.text(bean.getYeTai().getYtCode());
		xmlSerializer.endTag("", XMLStatic.YT);
		xmlSerializer.startTag("", XMLStatic.MDMJ);
        xmlSerializer.text(bean.getArea());
		xmlSerializer.endTag("", XMLStatic.MDMJ);
		xmlSerializer.startTag("", XMLStatic.REMARK);
        xmlSerializer.text(bean.getRemark());
		xmlSerializer.endTag("", XMLStatic.REMARK);
		xmlSerializer.startTag("", XMLStatic.SAOF);
        xmlSerializer.text(loginInfo.getSaof());
		xmlSerializer.endTag("", XMLStatic.SAOF);
		xmlSerializer.startTag("", XMLStatic.PERNR);
        xmlSerializer.text(loginInfo.getPernr());
		xmlSerializer.endTag("", XMLStatic.PERNR);
		
		xmlSerializer.endTag("", XMLStatic.RECORDS);
		xmlSerializer.endTag("", XMLStatic.CONTENT);
		xmlSerializer.endDocument();
		writer.flush();
		writer.close();
		return writer.toString().replace("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>", "");
	}
}
